<template>
    <div class="box">
        <el-row>
            <el-col :span="24">
                <div class="header">
                    <el-form ref="form" :model="form" label-width="100px" class="flex">
                        <el-form-item label="所属网点">
                            <el-select v-model="form.networkNameId" placeholder="请选择所属网点" style="width:286px">
                                        <el-option v-for="item in networkList" :key="item.id" :label="item.networkName"
                                            :value="item.id"></el-option>
                                    </el-select>
                        </el-form-item>
                        <el-form-item label="结算科目">
                            <el-select v-model="form.settleSubjectId" placeholder="请选择结算科目" style="width:286px">
                                        <el-option v-for="item in settleSubject" :key="item.id" :label="item.title"
                                            :value="item.id"></el-option>
                                    </el-select>
                        </el-form-item>
                        <el-form-item label="时间范围" style="width:500px">
                         <el-date-picker
      v-model="Time"
      type="daterange"
      @change="dateChange" 
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">
    </el-date-picker>
                        </el-form-item>
                        <el-form-item >
                            <el-button type="primary" @click="search">查询</el-button>
                            <el-button @click='clear'>重置</el-button>
                        </el-form-item>
                        <el-form-item label="结算类型" >
                            <el-select v-model="form.settleType" placeholder="请选择结算类型" style="width:286px">
                                        <el-option label="客户" value="客户"></el-option>
                                        <el-option label="承包区" value="承包区"></el-option>
                                        <el-option label="业务员" value="业务员"></el-option>
                                    </el-select>
                        </el-form-item>
                        <el-form-item label="结算对象" >
                            <el-input v-model="form.settleObject" placeholder="请选择结算对象"
                                        style="width:286px"></el-input>
                        </el-form-item>
                        <el-form-item label="收付类型" >
                            <el-select v-model="form.nwReceiptPayType" placeholder="请选择收付类型" style="width:286px">
                                        <el-option label="应收下级" value="应收下级"></el-option>
                                        <el-option label="应付下级" value="应付下级"></el-option>
                                    </el-select>
                        </el-form-item>
                        <el-form-item label="是否有效" >
                            <el-select v-model="form.effectiveStatus" placeholder="请选择是否有效" style="width:286px">
                                        <el-option label="无效" value="无效"></el-option>
                                        <el-option label="有效" value="有效"></el-option>
                                    </el-select>
                        </el-form-item>
                        
                    </el-form>
                </div>
            </el-col>
        </el-row>
        <el-row type="flex" justify="space-between">
            <el-col :span="6">
                <div>
                    当前页共10项
                </div>
            </el-col>
            <el-col :span="3">
                <div>
                    <el-button type="primary" >新增</el-button>
                    <el-button type="primary" >删除</el-button>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div>
                    <el-table ref="multipleTable"  :cell-style="{ textAlign: 'center' }" :header-cell-style="{ textAlign: 'center' }" :data="tableData" tooltip-effect="dark" style="width: 100%"
                        @selection-change="handleSelectionChange">
                        <el-table-column type="selection" width="55">
                        </el-table-column>
                        <el-table-column prop="businessTime" label="业务日期" >
                        </el-table-column>
                        <el-table-column prop="settleType" label="结算类型" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="settleObject" label="结算对象" >
                        </el-table-column>
                        <el-table-column prop="settleObjectCode" label="结算对象编号" >
                        </el-table-column>
                        <el-table-column prop="settleCycle" label="结算周期" >
                        </el-table-column>
                        <el-table-column prop="subject" label="科目" >
                        </el-table-column>
                        <el-table-column prop="collectPayType" label="收付类型" >
                        </el-table-column>
                        <el-table-column prop="amount" label="金额" >
                        </el-table-column>
                        <el-table-column prop="advancePaymentMoney" label="预付款已收金额" >
                        </el-table-column>
                        <el-table-column prop="effectiveStatus" label="有效状态" >
                        </el-table-column>
                        <el-table-column prop="createBy" label="创建人" >
                        </el-table-column>
                    </el-table>
                </div>
            </el-col>

        </el-row>
        <div class="block" style="display: flex; justify-content: end;">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="currentPage" :page-sizes="[100, 200, 300, 400]" :page-size="100"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { getOutletsList, settleSubjectList,storageChargeList,storageChargeSearch} from "@/api/dashboard";

export default {
    data() {
        return {
            networkList:[],
            settleSubject:[],
            form: {
                networkNameId: '',
                settleSubjectId:'',
                startTime: '',
                endTime: '',
                settleType:'',
                settleObject:'',
                effectiveStatus:''
            },
            Time:'',
            currentPage:1,
            tableData: [],
              pages: {
                pageNum: 1,
                pageSize: 10,
            },
            total: 0,
        };
    },
    created() {
        this.getTabList()
        this.getOutLet()
        this.getSettleSubject()
    },
    methods: {
        // 获取网点列表
        getOutLet() {
            getOutletsList().then((res) => {
                if (res.code == 200) {
                    this.networkList = res.data
                }
            })
        },
        // 获取结算科目
        getSettleSubject(){
            settleSubjectList().then((res) => {
                if (res.code == 200) {
                    this.settleSubject = res.data
                }
            })
        },
        // 获取表格数据
        getTabList(){
            storageChargeList(this.pages.pageNum,this.pages.pageSize).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.data
                    this.total = res.data.total
                    this.pages = res.data.pages
                }
            })
        },
         // 日期转换
        dateChange(value) {
            this.form.startTime = value[0]
            this.form.endTime = value[1]

        },
        search(){
             for (const key in this.form) {
                // Check if the value is empty (assuming empty means falsy in this context)
                if (!this.form[key]) {
                    // If the value is empty, delete the key from mxForm
                    delete this.form[key];
                }
            }
            storageChargeSearch(this.form).then((res) => {
                if (res.code == 200) {
                  this.tableData = res.data.data
                    this.total = res.data.total
                    this.pages = res.data.pages
                }
            })
        },
        // 重置
        clear() {
            this.form = {}
            this.getTabList()

        },
        handleSizeChange(val) {
            this.pages.pageSize = val
            this.getTabList()

            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.pages.pageNum = val
            this.getTabList()
            console.log(`当前页: ${val}`);
        },
        handleSelectionChange(val) {
            // this.multipleSelection = val;
        }
    },

}
</script>

<style lang="scss" scoped>
.box {
    padding: 20px;
}

.flex {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
}

.header {
    padding-bottom: 20px;
    border-bottom: 1px solid #ccc;
}

.el-row {
    margin-bottom: 20px;

    &:last-child {
        margin-bottom: 0;
    }
}

.el-col {
    border-radius: 4px;
}

.bg-purple-dark {
    background: #99a9bf;
}

.bg-purple {
    background: #d3dce6;
}

.bg-purple-light {
    background: #e5e9f2;
}

.grid-content {
    border-radius: 4px;
    min-height: 36px;
}

.row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
}
</style>